home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / viewers / pcshow / dfi.h < prev    next >
C/C++ Source or Header  |  1991-07-01  |  8KB  |  247 lines

  1. /*------------------------------------------------------------------------------
  2.  * File:     dfi.h
  3.  * Purpose:    HDF internal header file
  4.  * Invokes:    stdio.h, sys/file.h
  5.  * Contents: 
  6.  *    Compilation parameters
  7.  *    Machine-dependent definitions
  8.  *    Flexibility definitions: i/o buffering, dynamic memory, structure i/o
  9.  *    Size parameters
  10.  * Remarks: To port to a new system, only dfi.h and Makefile need be modified.
  11.  *            This file is included with user programs, but users do not see it.
  12.  *----------------------------------------------------------------------------*/
  13.  
  14.  
  15. #ifndef DF_MAGICK                    /* avoid re-inclusion */
  16.  
  17. #define DF_MAGICK        "\016\003\023\001"        /* ^N^C^S^A */
  18.  
  19. #ifndef FILE
  20. #include <stdio.h>
  21. #endif FILE
  22.  
  23.  
  24. /*--------------------------------------------------------------------------*/
  25. /*            Compilation Parameters for Flexibility and Portability             */
  26.  
  27.     /* modify this line to allow for machine dependencies */
  28. #define PC
  29.  
  30.     /* modify this line for buffered/unbuffered i/o */
  31. #define DF_BUFFIO
  32.  
  33.     /* modify this line for dynamic/static memory allocation */
  34. #define DF_DYNAMIC
  35.  
  36.     /* modify this line if structures cannot be read/written as is */
  37. #define DF_STRUCTOK
  38.  
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /*                                MT/NT constants                                */
  42. #define DFMT_SUN        0x1111
  43. #define DFMT_ALLIANT    0x1111
  44. #define DFMT_UNICOS        0x3331
  45. #define DFMT_CTSS        0x3331
  46. #define DFMT_VAX        0x2221
  47. #define DFMT_PC            0x1141                /* note byte swapping */
  48. #define DFMT_MAC        0x1111
  49.  
  50. #define DFNT_VERSION    1                    /* current version of NT info */
  51.     /* type info codes */
  52. #define DFNT_UINT        1
  53. #define    DFNT_INT        2
  54. #define DFNT_UCHAR        3
  55. #define DFNT_CHAR        4
  56. #define DFNT_FLOAT        5
  57. #define DFNT_DOUBLE        6
  58.     /* class info codes for int */
  59. #define DFNTI_MBO        1                    /* Motorola byte order 2's compl */
  60. #define DFNTI_VBO        2                    /* Vax byte order 2's compl */
  61. #define DFNTI_IBO        4                    /* Intel byte order 2's compl */
  62.     /* class info codes for float */
  63. #define DFNTF_IEEE        1                    /* IEEE format */
  64. #define DFNTF_VAX        2                    /* Vax format */
  65. #define DFNTF_CRAY        3                    /* Cray format */
  66.     /* class info codes for char */
  67. #define DFNTC_BYTE        0                    /* bitwise/numeric field */
  68. #define DFNTC_ASCII        1                    /* ASCII */
  69. #define DFNTC_EBCDIC    5                    /* EBCDIC */
  70.  
  71. /*--------------------------------------------------------------------------*/
  72. /*                        Machine dependencies                                */
  73. #ifdef PC
  74. #ifndef O_RDONLY
  75. #include <fcntl.h>
  76. #define L_INCR    1
  77. #endif O_RDONLY
  78. #define int16 int
  79. #define uint16 unsigned int
  80. #define int32 long int
  81. #define DFmovmem(from, to, len)    memcpy(to, from, len)
  82. #undef DF_STRUCTOK                    /* structure writing will not work on PC */
  83. #undef DF_BUFFIO                    /* unbuffered i/o is faster */
  84. long longswap();                    /* provided elsewhere */
  85.  
  86.     /* in the next 3 lines, p is recast so right number of bytes passed */
  87.     /* ### Note that all calls modify p.  Need to use temporary ptr */
  88. #define UINT16READ(p, x)    { x = intswap(*(int *)p); p+=2; }
  89. #define INT16READ(p, x)        { x = intswap(*(int *)p); p+=2; }
  90. #define INT32READ(p, x)        { x = longswap(*(long *)p); p+=4; }
  91. #define UINT16WRITE(p, x)    { *(int *)p = intswap(x); p+=2; }
  92. #define INT16WRITE(p, x)    { *(int *)p = intswap(x); p+=2; }
  93. #define INT32WRITE(p, x)    { *(long *)p = longswap(x); p+=4; }
  94. #define DF_CREAT(name, prot) creat(name, prot)
  95. #define DF_MT    DFMT_PC
  96. #endif PC
  97.  
  98.  
  99. #ifdef UNICOS
  100. #ifndef O_RDONLY
  101. #include <sys/fcntl.h>                /* for unbuffered i/o stuff */
  102. #define L_INCR    1
  103. #endif O_RDONLY
  104. #define int16 int
  105. #define uint16 int
  106. #define int32 int
  107. #define DFmovmem(from, to, len)    memcpy(to, from, len)
  108. #undef DF_STRUCTOK            /* cannot directly read/write structures */
  109. #define UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  110. #define INT16READ(p, x)        { x = (*p++)<<8; x |= (*p++) & 255; }
  111. #define INT32READ(p, x)        { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  112.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  113. #define UINT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  114. #define INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  115. #define INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;    \
  116.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  117. #define DF_CREAT(name, prot) creat(name, prot)
  118. #define DF_MT    DFMT_UNICOS
  119. #endif UNICOS
  120.  
  121.  
  122. #ifdef SUN
  123. #include <sys/file.h>                /* for unbuffered i/o stuff */
  124. #define int16 short
  125. #define uint16 unsigned short
  126. #define int32 long
  127. #define DFmovmem(from, to, len)    memcpy(to, from, len)
  128. #ifndef DF_STRUCTOK
  129. #define UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  130. #define INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  131. #define INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  132.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  133. #define UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  134. #define INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  135. #define INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;    \
  136.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  137. #endif DF_STRUCTOK
  138. #define DF_CREAT(name, prot) creat(name, prot)
  139. #define DF_MT    DFMT_SUN
  140. #endif SUN
  141.  
  142.  
  143. #ifdef ALLIANT
  144. #include <sys/file.h>                /* for unbuffered i/o stuff */
  145. #define int16 short
  146. #define uint16 unsigned short
  147. #define int32 long
  148. #define DFmovmem(from, to, len)    bcopy(from, to, len)
  149. #ifndef DF_STRUCTOK
  150. #define UINT16READ(p, x) { DFmovmem(p, &x, 2); p+=2; }
  151. #define INT16READ(p, x) { DFmovmem(p, &x, 2); p+=2; }
  152. #define INT32READ(p, x) { DFmovmem(p, &x, 4); p+=4; }
  153. #define UINT16WRITE(p, x) { DFmovmem(&x, p, 2); p+=2; }
  154. #define INT16WRITE(p, x) { DFmovmem(&x, p, 2); p+=2; }
  155. #define INT32WRITE(p, x) { DFmovmem(&x, p, 4); p+=4; }
  156. #endif DF_STRUCTOK
  157. #define DF_CREAT(name, prot) creat(name, prot)
  158. #define DF_MT    DFMT_ALLIANT
  159. #endif ALLIANT
  160.  
  161.  
  162. #ifdef MAC
  163. #include <Files.h>                /* for unbuffered i/o stuff */
  164. #define int16 short
  165. #define uint16 unsigned short
  166. #define int32 long
  167. #define DFmovmem(from, to, len)    memcpy(to, from, len)
  168. #ifndef DF_STRUCTOK
  169. #define UINT16READ(p, x) { DFmovmem(p, &x, 2); p+=2; }
  170. #define INT16READ(p, x) { DFmovmem(p, &x, 2); p+=2; }
  171. #define INT32READ(p, x) { DFmovmem(p, &x, 4); p+=4; }
  172. #define UINT16WRITE(p, x) { DFmovmem(&x, p, 2); p+=2; }
  173. #define INT16WRITE(p, x) { DFmovmem(&x, p, 2); p+=2; }
  174. #define INT32WRITE(p, x) { DFmovmem(&x, p, 4); p+=4; }
  175. #endif DF_STRUCTOK
  176. #define DF_CREAT(name, prot) creat(name, prot)
  177. #define DF_MT    DFMT_MAC
  178. #endif MAC
  179.  
  180.  
  181. /*--------------------------------------------------------------------------*/
  182. /*                        Flexibility parameters                                 */
  183.  
  184. #ifdef DF_BUFFIO            /* set all calls to do buffered I/O */
  185. #define DF_OPEN(x,y) fopen(x,y)
  186. #define DF_CLOSE(x) fclose(x)
  187. #define DF_SEEK(x,y,z) fseek(x,y,z)
  188. #define DF_SKEND(x,y,z) fseek(x,y,z)
  189. #define DF_TELL(x) ftell(x)
  190. #define DF_READ(a,b,c,d) fread(a,b,c,d)
  191. #define DF_WRITE(a,b,c,d) fwrite(a,b,c,d)
  192. #define DF_FLUSH(a) fflush(a)
  193. #ifdef PC
  194. #define DF_RDACCESS "rb"
  195. #define DF_WRACCESS "rb+"
  196. #else PC
  197. #define DF_RDACCESS "r"
  198. #define DF_WRACCESS "r+"
  199. #endif PC
  200.  
  201. #else DF_BUFFIO            /* unbuffered i/o */
  202. #define DF_OPEN(x,y) open(x,y)
  203. #define DF_CLOSE(x) close(x)
  204. #define DF_SEEK(x,y,z) lseek(x,y,z)
  205. #define DF_SKEND(x,y,z) lseek(x,-1*y,z)
  206. #define DF_TELL(x) lseek(x,0L,L_INCR)
  207. #define DF_READ(a,b,c,d) read(d,a,b*c)
  208. #define DF_WRITE(a,b,c,d) write(d,a,b*c)
  209. #define DF_FLUSH(a)                             /* no need to flush */
  210. #ifdef PC
  211. #define DF_RDACCESS O_RDONLY | O_RAW
  212. #define DF_WRACCESS O_RDWR | O_RAW
  213. #else PC
  214. #define DF_RDACCESS O_RDONLY
  215. #define DF_WRACCESS O_RDWR
  216. #endif PC
  217. #endif DF_BUFFIO
  218.  
  219.  
  220.     /* if not allocating memory dynamically, need buffer for compression */
  221. #ifndef DF_DYNAMIC
  222. #define DF_TBUF
  223. #endif DF_DYNAMIC
  224.  
  225.     /* if reading/writing structures not ok, need buffer for conversion */
  226. #ifndef DF_TBUF
  227. #ifndef DF_STRUCTOK
  228. #define DF_TBUF
  229. #endif DF_STRUCTOK
  230. #endif DF_TBUF
  231.  
  232.     /* set buffer size */
  233. #ifdef DF_TBUF
  234. #define DF_TBUFSZ    10000
  235. #ifndef DFMASTER
  236. extern
  237. #endif DFMASTER
  238.     unsigned char DFtbuf[DF_TBUFSZ];
  239. #endif DF_TBUF
  240.  
  241. /*--------------------------------------------------------------------------*/
  242. /*                            Size parameters                                    */
  243. #define DF_MAXDFS            32    /* How many DF's can be open at once */
  244. #define DF_DEFAULTDDS        16    /* How many DD's a file has by default */
  245.  
  246. #endif DF_MAGICK
  247.